package com.epro.dx.task;

import java.util.ArrayList;

import com.epro.dx.util.ActivityUtil;
import com.weipu.common.facade.exception.DxException;
import com.weipu.common.facade.factory.ProviderFactory;
import com.weipu.common.facade.support.service.task.BaseServiceTask;


/************************
 * @author Tony
 * @Date:2016-4-29下午3:20:30
 * @描述:点击通知时设置已读
 ************************/
public class SetNoticeReadTask extends
		BaseServiceTask<String> {

	private static final long serialVersionUID = -6221560093333502736L;
	private int actionType;
	private ArrayList<String> noticeIDs;
	public SetNoticeReadTask(int actionType,ArrayList<String> noticeIDs){
		this.actionType = actionType;
		this.noticeIDs = noticeIDs;
	}
	@Override
	protected boolean executeRequest() {
		return true;
	}
	@Override
	protected String execute() {
		int reTryCount = 0;
        
        String result = null;//接口返回结果
        do
        {
            reTryCount++;
            
            result = setRead();
            
            //重试次数超过3次，认为解锁失败，认为任务失败
            if (reTryCount > 3)
            {
                break;
            }
            
        } while (!"0".equals(result));//只要不成功则会重试解锁订单，最多尝试3此
		return result;
	}
	/**
	 * @创建：Tony 2016-5-9下午5:04:49
	 * @描述：调用消息回执接口
	 * @return
	 */
	private String setRead() {
		try {
			ProviderFactory.createMessageService().setNoticeRead(actionType, noticeIDs, ActivityUtil.getCustomerID(), ActivityUtil.getCustomerToken());
		} catch (DxException e) {
			return e.getErrCode();
		}
		return "0";
	}
	@Override
	public int hashCode() {
		return noticeIDs.get(0).hashCode();
	}
}
